﻿Imports System.Data.SqlClient
Public Class FormAddEditorStock
    Private Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles btnSave.Click
        If txtCode.Text = "" Then
            Dim cn As New SqlConnection()
            cn.ConnectionString = "server=WINCTRL-B8GV7ME;uid=sa;pwd=123;database=AppSaleDb;"
            cn.Open()
            Dim cmd As New SqlCommand()
            cmd.Connection = cn
            cmd.CommandText = "INSERT INTO tbl_Products VALUES (N'" & txtCode.Text & "',N'" & txtNamePro.Text & "',N'" & txtQty.Text & "',N'" & txtPriceIn.Text & "',N'" & txtTotalInPrice.Text & "',N'" & txtPriceOut.Text & "',N'" & dtpStock.Value.ToString("dd,MMMM,yyyy") & "') "
            cmd.ExecuteNonQuery()
        Else
            Dim cn As New SqlConnection()
            cn.ConnectionString = "server=WINCTRL-B8GV7ME;uid=sa;pwd=123;database=AppSaleDb;"
            cn.Open()
            Dim cmd As New SqlCommand()
            cmd.Connection = cn
            cmd.CommandText = "UPDATE tbl_Products SET Name =N'" & txtNamePro.Text & "',Qty =N'" & txtQty.Text & "',PriceIn=N'" & txtPriceIn.Text & "',PriceOut=N'" & txtPriceOut.Text & "',Date=N'" & dtpStock.Value.ToString("dd,MMMM,yyyy") & "' WHERE Code=N'" & txtCode.Text & "'"
            cmd.ExecuteNonQuery()
        End If
        Me.DialogResult = Windows.Forms.DialogResult.OK
    End Sub
    Private Sub txtQty_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtQty.KeyPress
    End Sub

    'Private Sub txtQty_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtQty.TextChanged
    '    If txtQty.Text = "" Then
    '        Exit Sub
    '    Else
    '        txtTotalInPrice.Text = Val(txtQty.Text) * Val(txtPriceIn.Text)
    '        txtPriceOut.Text = txtPriceIn.Text + (txtPriceIn.Text * 0.5)
    '    End If
    'End Sub

    Private Sub FormAddEditorStock_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class